package com.bkgy.modular.tbdsjruleeditrelation.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.tbdsjruleeditrelation.dao.TbDsjRuleEditRelationDao;
import com.bkgy.modular.tbdsjruleeditrelation.entity.JTbDsjRuleEditRelation;
import com.bkgy.modular.tbdsjruleeditrelation.entity.TbDsjRuleEditRelation;
import com.bkgy.modular.tbdsjruleeditrelation.service.TbDsjRuleEditRelationService;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 规则编辑器关联表接口具体实现类
* @author  生成器生成
* @date 2022-08-01 15:15:23
*/
@Service
public class TbDsjRuleEditRelationServiceImpl implements TbDsjRuleEditRelationService {
	
	@Autowired
	private TbDsjRuleEditRelationDao tbDsjRuleEditRelationDao;
	
	/**
     * 添加记录
     * @param data json字符串
     * @param userId 用户id
     * @param sname 用户姓名
     */
	public ResultData insertDataTbDsjRuleEditRelation(String data,Long userId,String sname){
		try{
			JTbDsjRuleEditRelation jtbDsjRuleEditRelation = JSON.parseObject(data,JTbDsjRuleEditRelation.class);
    		TbDsjRuleEditRelation tbDsjRuleEditRelation = jtbDsjRuleEditRelation.getTbDsjRuleEditRelation();
    		CodiUtil.newRecord(userId,sname,tbDsjRuleEditRelation);
            tbDsjRuleEditRelationDao.insertDataTbDsjRuleEditRelation(tbDsjRuleEditRelation);
            return ResultData.ResultDataSuccessSelf("添加数据成功", null);
    	}catch(Exception e){
    		e.printStackTrace();
    		return ResultData.ResultDataFaultSelf("添加失败，错误信息为" + e.getMessage(), null); 
    	}
	};
	
	/**
	 * 根据主键删除对象
	 * @param indocno  对象主键
	 * */
	public ResultData deleteDataTbDsjRuleEditRelationOne(Long indocno){
		try {
            tbDsjRuleEditRelationDao.deleteDataTbDsjRuleEditRelationOne(indocno);
             return ResultData.ResultDataSuccessSelf("删除数据成功", null);
        } catch (Exception e) {
        	e.printStackTrace();
        	return ResultData.ResultDataFaultSelf("删除失败,失败信息为" + e.getMessage(), null); 
        }
	};
	
	/**
     * 根据主键字符串删除多个对象
     * @param str_id 对象主键字符串
     */
    public ResultData deleteDataTbDsjRuleEditRelationMany(Long str_id) {
        try {
        	String sql = "delete tb_dsj_rule_edit_relation where rule_edit_variable in(" + str_id +")";
            tbDsjRuleEditRelationDao.deleteDataTbDsjRuleEditRelationMany(sql);
            return ResultData.ResultDataSuccessSelf("删除数据数据成功", null);
        } catch (Exception e) {
        	e.printStackTrace();
        	return ResultData.ResultDataFaultSelf("删除失败,失败信息为" + e.getMessage(), null); 
        }
    }
	
	/**
     * 修改记录
     * @param userId 用户id
     * @param sname 用户姓名
     * @param data sysUser 对象实体
     */
	public ResultData updateDataTbDsjRuleEditRelation(String data,Long userId,String sname){
		try {
			JTbDsjRuleEditRelation jtbDsjRuleEditRelation = JSON.parseObject(data,JTbDsjRuleEditRelation.class);
    		TbDsjRuleEditRelation tbDsjRuleEditRelation = jtbDsjRuleEditRelation.getTbDsjRuleEditRelation();
        	CodiUtil.editRecord(userId,sname,tbDsjRuleEditRelation);
            tbDsjRuleEditRelationDao.updateDataTbDsjRuleEditRelation(tbDsjRuleEditRelation);
            return ResultData.ResultDataSuccessSelf("修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("修改失败,失败信息为" + e.getMessage(), null); 
        }
	};
	
	/**
     * 分页查看记录
     * @param data 分页参数字符串
     */
    public ResultData findDataTbDsjRuleEditRelationByPage(String data) {
        try {
        	JTbDsjRuleEditRelation jtbDsjRuleEditRelation = JSON.parseObject(data, JTbDsjRuleEditRelation.class); 
        	JSONObject jsonObject  = null;
        	Integer pageIndex = jtbDsjRuleEditRelation.getPageIndex();
        	Integer pageSize = jtbDsjRuleEditRelation.getPageSize();
        	
        	/*if(null == pageIndex || null == pageSize){
        		return ResultData.ResultDataFaultSelf("分页参数没有传", null); 
        	}*/
        	
        	if(null!=jtbDsjRuleEditRelation.getCondition()){
    			jsonObject  = JSON.parseObject(jtbDsjRuleEditRelation.getCondition().toString());
    		}
    
    		List<TbDsjRuleEditRelation> list = tbDsjRuleEditRelationDao.findDataTbDsjRuleEditRelationByPage(0, 0);
    		//Integer count = tbDsjRuleEditRelationDao.findDataTbDsjRuleEditRelationByPageSize();
    		return ResultData.ResultDataSuccess(list, 0);
        } catch (Exception e) {
        	e.printStackTrace();
        	return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null); 
        }
    }
    
    /**
     * 根据主键查询单条记录
     * @param data 分页参数字符串
     */
    public ResultData findDataTbDsjRuleEditRelationByIndocno(String data) {
        try {
        	JTbDsjRuleEditRelation jtbDsjRuleEditRelation = JSON.parseObject(data, JTbDsjRuleEditRelation.class); 
        	Long indocno = jtbDsjRuleEditRelation.getIndocno();
        	
    		TbDsjRuleEditRelation tbDsjRuleEditRelation = tbDsjRuleEditRelationDao.findDataTbDsjRuleEditRelationByIndocno(indocno);
    		return ResultData.ResultDataSuccess(tbDsjRuleEditRelation);
        } catch (Exception e) {
        	e.printStackTrace();
        	return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null); 
        }
    }
	
	/**
	 * 查看记录
	 * @return list 对象集合返回
	 * */
	public List<TbDsjRuleEditRelation> findDataTbDsjRuleEditRelation(){
		List<TbDsjRuleEditRelation> list = tbDsjRuleEditRelationDao.findDataTbDsjRuleEditRelation();
		return list;
	};
}
